package com.sailing.xjpb.ipaas.client.config;

import com.sailing.xjpb.ipaas.client.core.IpaasSsoFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * IpaasFilter配置类
 *
 * @author YW
 */
@EnableConfigurationProperties(IpaasClientProperties.class)
@ConditionalOnClass(name = "javax.servlet.Filter")
@Configuration
public class IpaasFilterAutoConfiguration {

    @Bean
    public FilterRegistrationBean<IpaasSsoFilter> registerIpaasSsoFilter() {
        FilterRegistrationBean<IpaasSsoFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(ipaasSsoFilter());
        registration.addUrlPatterns("/*");
        registration.setName("ipaasSsoFilter");
        // 值越小，Filter越靠前。
        registration.setOrder(Integer.MIN_VALUE);
        return registration;
    }

    @Bean
    public IpaasSsoFilter ipaasSsoFilter() {
        return new IpaasSsoFilter();
    }

}
